<%--
    Document   : squadsContent
    Created on : Nov 23, 2012, 2:14:54 PM
    Author     : newohybat
--%>

<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>

<s:useActionBean beanclass="cz.muni.fi.pa165.ddtroops.web.actionbeans.SquadActionBean" var="actionBean"/>
<div class="txt">
    <h2><s:label for="squad.list"/></h2>
</div>
<c:if test="${not empty pageContext.request.getParameter('error')}">
    <div class="error">
        <b><s:label for="error.${pageContext.request.getParameter('error')}"/></b>
    </div>
</c:if>
<c:if test="${pageContext.request.isUserInRole('ROLE_SUPERVISOR')}">
    <div class="raceForm">
        <tiles:insertDefinition name="dd-troops-web.squads-createForm" />
    </div>
</c:if>
<ul class="raceList">
<c:forEach items="${actionBean.squads}" var="squad">
    <li class="raceThumbnail">
        <p class="raceName"><s:label for="squad.name"/>:<c:out value="${squad.name}"/></p>
        <p>
            <s:label for="squad.description"/>:
            <c:choose>
                <c:when test="${squad.description.length() < 75}">
                    <c:out value="${squad.description}"/>
                </c:when>
                <c:otherwise>
                    <c:out value="${squad.description.substring(0,73)}"/>...
                </c:otherwise>
            </c:choose>
        </p>
        <p>
            <s:label for="squad.task"/>:&nbsp;<c:out value="${squad.task}"/><br/>
        </p>
        <p>
            <s:label for="squad.gold"/>:&nbsp;<c:out value="${squad.gold}"/><br/>
        </p>
        <p>
            <s:label for="squad.leader"/>:&nbsp;<c:out value="${squad.leader.name}"/><br/>
        </p>
        <div class="raceBonuses">
            <s:label for="squad.members"/>:<br />
            <c:forEach items="${squad.members}" var="member">
                    <c:out value="${member.name}"/><br />
            </c:forEach>
        </div>
        <c:if test="${!actionBean.isMemberOwner(squad.id, pageContext.request.getRemoteUser())}">
            <div class="raceLinks">
                <s:link beanclass="cz.muni.fi.pa165.ddtroops.web.actionbeans.SquadActionBean" event="delete" class="delete">
                    <s:param name="squad.getId()" value="${squad.id}"/>
                    <img src="<%=request.getContextPath()%>/images/deleteIcon.gif"/>
                </s:link>
                <br/>
                <s:link beanclass="cz.muni.fi.pa165.ddtroops.web.actionbeans.SquadActionBean" event="edit">
                    <s:param name="squad.getId()" value="${squad.id}"/>
                    <img src="<%=request.getContextPath()%>/images/editIcon.png"/>
                </s:link>
            </div>
        </c:if>
    </li>
</c:forEach>
</ul>
